import 'package:flutter/material.dart';
import '../../share/my_color.dart';

typedef VoidCallback = void Function(bool);

//单选按钮 -- 热门标签
//ChoiceChip 简单版
class ShowChoiceButtonWidget extends StatelessWidget {
  final bool selected;
  final double height;
  final double minWidth;
  final EdgeInsetsGeometry padding;
  final VoidCallback? onTop;
  final Color norBgColor;
  final Color selectBgColor;
  final Color textNorColor;
  final Color textSelectColor;
  final double font;
  final double radius;
  final String title;
  final List<BoxShadow>? boxShadow;
  final Gradient? gradient;
  final Widget? child;

  ShowChoiceButtonWidget({
    Key? key,
    this.onTop,
    this.selected = false,
    required this.title,
    this.height = 24,
    this.minWidth = 60,
    this.padding = const EdgeInsets.symmetric(horizontal: 12),
    this.font = 12,
    this.norBgColor = MyColors.color_245_245_245,
    this.selectBgColor = MyColors.color_247_73_60,
    this.textNorColor = MyColors.color_34_34_34,
    this.textSelectColor = MyColors.color_255_255_255,
    this.radius = 12,
    this.boxShadow,
    this.gradient,
    this.child, //如果传了则使用 child
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget icon = this.child == null
        ? Text(
            title,
            style: TextStyle(
              color: selected ? textSelectColor : textNorColor,
              fontSize: font,
            ),
          )
        : child!;
    return ButtonTheme(
      minWidth: minWidth,
      height: height,
      padding: padding,
      materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
      child: Container(
        decoration: BoxDecoration(
          color: gradient == null ? (selected ? selectBgColor : norBgColor) : null,
          borderRadius: BorderRadius.circular(radius),
          gradient: gradient,
          boxShadow: boxShadow,
        ),
        child: FlatButton(
          splashColor: Colors.transparent,
          onPressed: () {
            if(onTop !=null){
              onTop!(true);
            }
          },
          child: icon,
        ),
      ),
    );
  }
}
